package com.fullstack.app.pages

import cats.effect.*
import tyrian.{Cmd, Html, Sub}
import com.fullstack.app.App
import com.fullstack.app.pages.home.{HomePage, UserPage}


abstract class Page {
  
  def initCmd: Cmd[IO, App.Msg]

  def update(msg: App.Msg): (Page, Cmd[IO, App.Msg])

  def view(): Html[App.Msg]

  def subscriptions(): Sub[IO, App.Msg] =
    Sub.None

}

object Page {
  

  enum StatusKind:
    case SUCCESS, ERROR, LOADING

  case class Status(message: String, kind: StatusKind)

  object urls {
    
    // 首页
    val homePage = "/home"
    
    val userPage = "/user"

    val empty =  ""
    val home =  "/"
  }

  import urls.*
  def getPage(location: String) =
    location match
      
      case `homePage`                            => HomePage()

      case `userPage`                            => UserPage()
      
      case `empty` | `home`                      => HomePage()
      case _                                     => NotFoundPage()

}


